//
//  HTBannerView.swift
//  MagaCore
//
//  Created by MrMessy on 2023/5/4.
//

import SwiftUI

struct HTBannerView: View {

  @State var var_banners = []
  @State private var var_snappedItem = 0.0
  @State private var var_draggingItem = 0.0
  @State var var_activeIndex: Int = 0
  @State private var var_currentIndex = 0
  @State private var var_id: String = ""
  @State private var var_pushToVideoDetail = false

  var body: some View {
    
    VStack {
      NavigationLink(destination: HTVideoDetailScreen(var_id: var_id, var_source: "9"), isActive: $var_pushToVideoDetail) {
        EmptyView()
      }

      HTCarousel(var_items: $var_banners,
                 var_currentIndex: $var_currentIndex,
                 var_spacing: UIDevice.ht_fixToWidth(width: -50),
                 var_itemWidth: UIDevice.ht_fixToWidth(width: 108),
                 var_itemHeight: UIDevice.ht_fixToWidth(width: 160),
                 var_opacity: 0.1,
                 var_sizeScale: 0.2,
                 var_autoScrollTime: 5) { item  in
        let var_anime = item as! HTAnime
        HTCoverView(var_anime: var_anime, var_showDUB: true, var_width: UIDevice.ht_fixToWidth(width: 108), var_height: UIDevice.ht_fixToWidth(width: 160))
          .onTapGesture {
            var_id = var_anime.var_banner_animeId
            var_pushToVideoDetail = true
            HTNetworkManager().ht_requestForBuried(.htEnumMomeMClNew(var_kid: "4", var_c_id: var_anime.var_banner_animeId, var_c_name: var_anime.var_title ?? ""))
          }
      }

      Text((var_banners as! [HTAnime])[var_currentIndex].var_title ?? "")
        .font(.system(size: UIDevice.ht_fixToWidth(width: 14)))
        .ht_normal()
        .lineLimit(1)
        .padding(.horizontal, 60)
    }
    .frame(maxWidth: .infinity)
  }
}
